<?php
// +----------------------------------------------------------------------
// | [ WE ONLY DO WHAT IS NECESSARY ]
// +----------------------------------------------------------------------
// | Author < 931274989@qq.com >
// +----------------------------------------------------------------------
// | Explain 洗车
// +----------------------------------------------------------------------
namespace app\ymkj\controller;

use think\facade\Session;
use think\facade\Config;
use think\Controller;
use think\Db;

 
class Payapi extends Controller
{
  public function returl()
  {
    $data = input();
    $user = Session::get('wewhat_user');
    $start_time = time();
    $end_time = time()+365*24*60*60;
    $chongzhi = Db::name('order')->where('id','=',$data['reqsn'])->value('name');
    $order = Db::name('order')->where('id','=',$data['reqsn'])->update(['type' => 1]);
    if($chongzhi == '会员充值'){
       $this->fenxiao($data['trxamt']/100);
       $result = Db::name('user')
       ->where('openid','=',$user['openid'])
       ->update(['vip'=>1,'bolishui'=>12,'start_time' =>$start_time,'end_time'=>$end_time]);
       $this->success('消费成功',url("user/index"));
    }else{
    	$this->success('消费成功',url("qcfu/index"));
    }
  }
  

  public function notify_url()
  {
    $data = input();
    $user = Session::get('wewhat_user');
    $start_time = time();
    $end_time = time()+365*24*60*60;
    $chongzhi = Db::name('order')->where('id','=',$data['reqsn'])->value('name');
    $order = Db::name('order')->where('id','=',$data['reqsn'])->update(['type' => 1]);
    if($chongzhi == '会员充值'){
       $this->fenxiao($data['trxamt']/100);
       $result = Db::name('user')
       ->where('openid','=',$user['openid'])
       ->update(['vip'=>1,'bolishui'=>12,'start_time' =>$start_time,'end_time'=>$end_time]);
       echo "success";
    }else{
    	echo "success";
    }
    
  }
  


  // 分销
  public function fenxiao($jine)
  {
    $user = Session::get('wewhat_user');
    $fenxiao = Db::name('fenxiao')->where('fenxiao','=','fenxiao')->find();
    $wxuser = Db::name('user')->where('openid','=',$user['openid'])->find();
    if($fenxiao['status'] == 1 && $fenxiao['type'] == 1){ // 百分比分销
      $f1 = Db::name('user')->where('openid','=',$wxuser['f1'])->setInc('balance',$jine*$fenxiao['f1']/100);
      $f2 = Db::name('user')->where('openid','=',$wxuser['f2'])->setInc('balance',$jine*$fenxiao['f2']/100);
      $f3 = Db::name('user')->where('openid','=',$wxuser['f3'])->setInc('balance',$jine*$fenxiao['f3']/100);
    }
    if($fenxiao['status'] == 1 && $fenxiao['type'] == 2){ // 固定金额
      $f1 = Db::name('user')->where('openid','=',$wxuser['f1'])->setInc('balance',$fenxiao['f1']*100);
      $f2 = Db::name('user')->where('openid','=',$wxuser['f2'])->setInc('balance',$fenxiao['f2']*100);
      $f3 = Db::name('user')->where('openid','=',$wxuser['f3'])->setInc('balance',$fenxiao['f3']*100);
    }
  }

  
}
?>